home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / phone / qu2ph_send.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-11  |  10.0 KB  |  347 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3.  
  4. /*
  5.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  6.  *
  7.  *
  8.  *     Copyright (C) 1979,1980,1981  University of Delaware
  9.  *
  10.  *     Department of Electrical Engineering
  11.  *     University of Delaware
  12.  *     Newark, Delaware  19711
  13.  *
  14.  *     Phone:  (302) 738-1163
  15.  *
  16.  *
  17.  *     This program module was developed as part of the University
  18.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  19.  *
  20.  *     Acquisition, use, and distribution of this module and its listings
  21.  *     are subject restricted to the terms of a license agreement.
  22.  *     Documents describing systems using this module must cite its source.
  23.  *
  24.  *     The above statements must be retained with all copies of this
  25.  *     program and may not be removed without the consent of the
  26.  *     University of Delaware.
  27.  *     
  28.  *
  29.  *     version  -1    David H. Crocker    March   1979
  30.  *     version   0    David H. Crocker    April   1980
  31.  *     version  v7    David H. Crocker    May     1981
  32.  *     version   1    David H. Crocker    October 1981
  33.  *
  34.  */
  35. /*  CH_PHONE:  deliver-to-phone transmission                            */
  36. /*                                                                      */
  37.  
  38. /*  Jun 81  D. Crocker      Add d2p_nadrs mechanism to send no msg text
  39.  *                          when there are not valid addresses
  40.  *  Jul 81  D. Crocker      Change state variable values, for more robust
  41.  *                          state diagrams, to avoid hang with Deliver
  42.  */
  43.  
  44.  
  45. #include "ch.h"
  46. #include "chan.h"
  47. #include "phs.h"
  48. #include "ap.h"
  49.  
  50. extern struct ll_struct  *logptr;
  51. extern Chan *curchan;
  52. extern char *strdup();
  53. extern char *ap_p2s();
  54. extern int  ap_outtype;
  55. extern char *supportaddr;
  56. extern char *mmdflogin;
  57.  
  58. /*#define RUNALON   */
  59.  
  60. LOCVAR int numadrs;                    /* number of valid addresses          */
  61. LOCVAR char *sender = (char *)NULL;    /* return address for message         */
  62. LOCVAR char *adr    = (char *)NULL;    /* recipient address                  */
  63. LOCVAR struct rp_construct
  64.                 rp_hend  =
  65. {
  66.     RP_NOOP, 'e', 'n', 'd', ' ', 'o', 'f', ' ', 'h', 'o', 's', 't', ' ',
  67.     'i', 'g', 'n', 'o', 'r', 'e', 'd', '\0'
  68. };
  69.  
  70. char ph_state = SND_RINIT;  /* state of processing current msg    */
  71.  
  72.  
  73. qu2ph_send (chname)                 /* overall mngmt for batch of msgs    */
  74.     char chname[];                /* name of channel we are             */
  75. {
  76.     short     result;
  77.     char    info[LINESIZE],
  78.         sendbuf[ADDRSIZE];
  79.  
  80.     if (rp_isbad (result = qu_pkinit ()))
  81.     return (result);
  82.  
  83.     if (rp_isbad (result = ph_sbinit ()))
  84.     {
  85.     printx ("remote site refuses to receive mail... ");
  86.     return (result);
  87.     }
  88.  
  89.     ph_state = SND_ABORT;
  90.     for(;;){
  91.     AP_ptr  loctree, domtree, routree, sendtree;
  92.     AP_ptr  ap_s2tree(), ap_normalize();
  93.  
  94.     result = qu_rinit (info, sendbuf, curchan->ch_apout);
  95.     if(rp_gval(result) == RP_NS){
  96.         qu_rend();
  97.         continue;
  98.     }
  99.     if(rp_gval(result) == RP_DONE)
  100.         break;
  101.  
  102.     if (rp_gval(result) == RP_FIO)          /* Can't open message file */
  103.         continue;
  104.     else if (rp_gval(result) != RP_OK)      /* Some other error */
  105.         break;
  106.  
  107.     if (sender != (char *)NULL){
  108.         free (sender);
  109.         sender = NULL;
  110.     }
  111.  
  112.     if ( sendbuf[0] == '\0' ||
  113.         (sendtree = ap_s2tree( sendbuf )) == (AP_ptr) NOTOK) {
  114.         printx("return address unparseable, using Orphanage\n");
  115.         fflush(stdout);
  116.         if ((sendtree = ap_s2tree( supportaddr )) == (AP_ptr) NOTOK) {
  117.             printx("Orphanage unparseable, using MMDF\n");
  118.             fflush(stdout);
  119.             if ((sendtree = ap_s2tree( mmdflogin )) == (AP_ptr) NOTOK) {
  120.             result = RP_PARM;
  121.             qu_rend();
  122.             continue;
  123.             }
  124.         }
  125.     }
  126.     ap_outtype = curchan -> ch_apout;
  127.     sendtree = ap_normalize (curchan -> ch_lname,
  128.             curchan  -> ch_ldomain, sendtree, curchan);
  129.     if(sendtree == (AP_ptr)MAYBE){
  130.         result = RP_NS;
  131.         qu_rend();
  132.         continue;
  133.     }
  134.     ap_t2parts (sendtree, (AP_ptr *)0, (AP_ptr *)0, &loctree,
  135.             &domtree, &routree);
  136.     sender = ap_p2s ((AP_ptr)0, (AP_ptr)0, loctree, domtree, routree);
  137.     if(sender == (char *)MAYBE){
  138.         result = RP_NS;
  139.         qu_rend();
  140.         continue;
  141.     }
  142.     ap_sqdelete( sendtree, (AP_ptr) 0 );
  143.     ap_free( sendtree );
  144.  
  145.     ph_state = SND_RDADR;
  146.     if (rp_isbad (result = ph_winit (chname, info, sender)))
  147.         return (result);      /* ready to process a message         */
  148.  
  149.     if (rp_isbad (result = q2p_admng ()))
  150.         return (result);      /* send the address list              */
  151.  
  152.     if (rp_gval (result) != RP_DONE)
  153.         break;                /* catch protocol errors              */
  154.  
  155.     if (rp_isbad (result = q2p_txmng ()))
  156.         return (result);      /* send the message text              */
  157.  
  158.     qu_rend();
  159.     }
  160.     qu_rend();
  161.  
  162.     if (rp_gval (result) != RP_DONE)
  163.     {
  164.     ll_log (logptr, LLOGTMP, "not DONE (%s)", rp_valstr (result));
  165.     return (RP_RPLY);         /* catch protocol errors              */
  166.     }
  167.  
  168. bugout:
  169.     ph_state = SND_ABORT;
  170.     qu_pkend ();                  /* done getting messages              */
  171.     if (rp_isbad (result = ph_sbend ()))
  172.                   /* done sending messages              */
  173.     printx ("bad ending for outgoing submission... ");
  174.  
  175.     return (result);
  176. }
  177. /* */
  178.  
  179. LOCFUN
  180.     q2p_admng ()              /* send address list                  */
  181. {
  182.     struct rp_bufstruct thereply;
  183.     short     result;
  184.     int       len;
  185.     char    host[ADDRSIZE];
  186.     char    adrbuf[ADDRSIZE];
  187.  
  188.     AP_ptr  loctree, domtree, routree, adrtree;
  189.     AP_ptr  ap_s2tree(), ap_normalize();
  190.  
  191.     for (numadrs = 0; ; )         /* reset for each new messages        */
  192.     {                             /* we already have and adr            */
  193.     ph_state = SND_ABORT;
  194.     result = qu_radr (host, adrbuf);
  195.     if (rp_isbad (result))
  196.         return (result);      /* get address from Deliver           */
  197.  
  198.     if (rp_gval (result) == RP_HOK)
  199.     {                         /* no-op the sub-list indication      */
  200.         qu_wrply ((struct rp_bufstruct *) &rp_hend, rp_conlen (rp_hend));
  201.         continue;
  202.     }
  203.  
  204.     if (rp_gval (result) == RP_DONE)
  205.         break;                /* end of address list                */
  206.  
  207.     if (adr != (char *)NULL)
  208.         free (adr);
  209.  
  210.     if ( (adrtree = ap_s2tree(adrbuf)) == (AP_ptr) NOTOK)  {
  211.         adr = strdup( adrbuf );
  212.     } else {
  213.         ap_outtype = curchan -> ch_apout;
  214.         adrtree = ap_normalize (curchan -> ch_lname,
  215.                 curchan  -> ch_ldomain, adrtree, curchan);
  216.         if(adrtree == (AP_ptr)MAYBE){
  217.         result = RP_NS;
  218.         goto bugout;
  219.         }
  220.         ap_t2parts (adrtree, (AP_ptr *)0, (AP_ptr *)0, &loctree,
  221.             &domtree, &routree);
  222.         adr = ap_p2s ((AP_ptr)0, (AP_ptr)0, loctree, domtree, routree);
  223.         if(adr == (char *)MAYBE){
  224.         result = RP_NS;
  225.         goto bugout;
  226.         }
  227.         ap_sqdelete( adrtree, (AP_ptr) 0 );
  228.         ap_free( adrtree );
  229.     }
  230.  
  231.     ph_state = SND_ARPLY;
  232.     if (rp_isbad (result = ph_wadr (host, adr)))
  233.         return (result);      /* give to remote site                */
  234.  
  235.     if (rp_isbad (result = ph_rrply (&thereply, &len)))
  236.         return (result);      /* how did remote like it?            */
  237.  
  238. bugout:
  239.     switch (rp_gval (thereply.rp_val))
  240.     {                         /* was address acceptable?            */
  241.         case RP_AOK:          /* address ok, text not yet sent      */
  242.         numadrs++;
  243.         ph_state = SND_ABORT;
  244.         qu_wrply (&thereply, len);
  245.         break;
  246.  
  247.         case RP_NO:           /* remaining acceptible responses     */
  248.         thereply.rp_val = RP_NDEL;
  249.         case RP_NS:
  250.         case RP_USER:
  251.         case RP_NDEL:
  252.         case RP_AGN:
  253.         case RP_NOOP:
  254.         ph_state = SND_ABORT;
  255.         qu_wrply (&thereply, len);
  256.         break;
  257.  
  258.         default:              /* responses which force abort        */
  259.         if (rp_isbad (thereply.rp_val))
  260.             return (thereply.rp_val);
  261.         return (RP_RPLY);
  262.     }
  263.     }
  264.     ph_state = SND_TRPLY;
  265.     return (ph_waend ());        /* tell remote of address list end    */
  266. }
  267. /* */
  268.  
  269. LOCFUN
  270.     q2p_txmng ()              /* send message text                  */
  271. {
  272.     struct rp_bufstruct thereply;
  273.     int     len;
  274.     short   result;
  275.     char    buffer[BUFSIZ];
  276.     static char faktxt[] = "   ";       /* to keep dial happy   */
  277.  
  278. /*  the main portion handles normal transmission, when there have been
  279.  *  some addresses accepted.  when no addresses have been accepted, then
  280.  *  the text will be ignored by the receiving side.  due to a problem
  281.  *  with the dial package, you must send some text.  this is handled
  282.  *  in the 'else' condition.
  283.  */
  284.     printx ("\tsending text...:");
  285.     fflush (stdout);
  286.     if (numadrs > 0)            /* really need to send the text       */
  287.     {
  288.     len = sizeof(buffer);
  289.     for (qu_rtinit (0L);
  290.         (rp_gval (result = qu_rtxt (buffer, &len))) == RP_OK; )
  291.     {
  292.         printx (".");         /* to show watcher we're working      */
  293.         fflush (stdout);
  294.         if (rp_isbad (result = ph_wtxt (buffer, len)))
  295.         return (result);                         
  296.         if (rp_gval (result) != RP_OK)
  297.         return (RP_RPLY);
  298.         len = sizeof(buffer);
  299.     }
  300.     printx (" ");             /* keep it pretty                     */
  301.     fflush (stdout);
  302.  
  303.     if (rp_isbad (result))
  304.         return (result);
  305.     if (rp_gval (result) != RP_DONE)
  306.         return (RP_RPLY);     /* didn't get it all across?          */
  307.     }
  308.     else                          /* send some text to keep dial happy  */
  309.     {
  310.     if (rp_isbad (result = ph_wtxt (faktxt, (sizeof faktxt) - 1)))
  311.         return (result);
  312.     if (rp_gval (result) != RP_OK)
  313.         return (RP_RPLY);
  314.     }
  315.  
  316.  
  317.     if (rp_isbad (result = ph_wtend ()))
  318.     return (result);          /* flag end of message                */
  319.  
  320.     if (rp_isbad (result = ph_rrply (&thereply, &len)))
  321.     return (result);          /* problem getting reply?             */
  322.  
  323.     switch (rp_gval (thereply.rp_val))
  324.     {                             /* was text acceptable?               */
  325.     case RP_OK: 
  326.         thereply.rp_val = RP_MOK;
  327.     case RP_MOK:              /* text was accepted                  */
  328.         qu_wrply (&thereply, len);
  329.         break;
  330.  
  331.     case RP_NO:               /* remaining acceptible responses     */
  332.         thereply.rp_val = RP_NDEL;
  333.     case RP_NDEL: 
  334.     case RP_AGN: 
  335.     case RP_NOOP: 
  336.         qu_wrply (&thereply, len);
  337.         thereply.rp_val = RP_OK;
  338.         break;                /* don't abort process                */
  339.  
  340.     default:                  /* responses which force abort        */
  341.         if (rp_isbad (thereply.rp_val))
  342.         return (thereply.rp_val);
  343.         return (RP_RPLY);
  344.     }
  345.     return (thereply.rp_val);     /* just quote remote                  */
  346. }
  347.